// src/api/foodStore.js
// 美食店铺相关API接口

/**
 * 获取店铺详情列表
 * @param {number} storeId
 * @returns {Promise} 店铺详情列表
 */
export async function getFoodStoreDetails(storeId) {
  try {
    const response = await fetch(`/api/foodStore/details/${storeId}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      }
    })

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`)
    }

    const result = await response.json()
    
    if (result.code === 200) {
        console.log(result.data);
        
      return result.data
    } else {
      throw new Error(`API error: ${result.msg}`)
    }
  } catch (error) {
    console.error('获取店铺详情失败:', error.message)
    throw error // 抛出错误让调用方处理
  }
}

/**
 * 根据ID获取单个店铺详情
 * @param {number} storeId - 店铺ID
 * @param {object} storeData
 * @returns {Promise} 店铺详情
 */
export async function updateFoodStoreById(storeId,storeData) {
  try {
    const response = await fetch(`${BASE_URL}/admin/foodStore/update/${storeId}`, {
      method: 'PUT',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(storeData)
    })

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`)
    }

    const result = await response.json()
    
    if (result.code === 200) {
      return result.data
    } else {
      throw new Error(result.msg || '更新店铺信息失败')
    }
  } catch (error) {
    console.error('获取店铺详情失败:', error)
    throw error // 抛出错误让调用方处理
  }
}
